*******************************************
/***Since the well data from 
IHS Markit Energy is proprietory,
we anonymize county and bank ID***/
*******************************************

cd "..."
***********************************
****CRA sample****
clear
use data_cra

/*Table 1 Panel B*/
tabstat amnt if boom_county==0 & boom_adj_county==0 & boom_msa==0 & inlist(size,0), stat(n mean sd p25 p50 p75)
tabstat s12 if boom_county==0 & boom_adj_county==0 & boom_msa==0 & inlist(size,0), stat(n mean sd p25 p50 p75)
tabstat s4 if boom_county==0 & boom_adj_county==0 & boom_msa==0 & inlist(size,0), stat(n mean sd p25 p50 p75)

************
/*Table 4*/
ivreghdfe lamnt (xboom inter3_cv=xboom_iv inter3_iv) if l_liqs<. & boom_county==0 & boom_adj_county==0 & boom_msa==0 & inlist(size,12,3), absorb(rssd_id#county#size county#year) cluster(rssd_id)
estimates store t1
ivreghdfe lamnt l_lasset l_lev l_liqs l_cis l_tier1 l_deps (xboom inter3_cv=xboom_iv inter3_iv) if boom_county==0 & boom_adj_county==0 & boom_msa==0 & inlist(size,12,3), absorb(rssd_id#county#size county#year) cluster(rssd_id)
estimates store t2
ivreghdfe lamnt (xboom inter5_cv=xboom_iv inter5_iv) if l_liqs<. & boom_county==0 & boom_adj_county==0 & boom_msa==0 & inlist(size,4,5), absorb(rssd_id#county#size county#year) cluster(rssd_id)
estimates store t3
ivreghdfe lamnt l_lasset l_lev l_liqs l_cis l_tier1 l_deps (xboom inter5_cv=xboom_iv inter5_iv) if boom_county==0 & boom_adj_county==0 & boom_msa==0 & inlist(size,4,5), absorb(rssd_id#county#size county#year) cluster(rssd_id)
estimates store t4

/*Compute the overall R-Squared for each regression above*/
matrix R=J(1,4,0)
forval i=1/4{
cap drop e_sample 
cap drop yy
est restore t`i'
gen e_sample=e(sample)
local rss=e(rss)
local depvar=e(depvar)
cap sum `depvar' if e_sample==1
gen yy=(`depvar'-r(mean))^2
cap total yy if e_sample==1
matrix r=e(b)
matrix R[1,`i']=1-`rss'/r[1,1]
}
cap drop yy
matrix list R


***********************************
****SBA sample****
clear
use data_sba

*********************
/*Table 10 Panel A*/
ivreghdfe lamnt0 (xboom=xboom_iv) if boom_county==0 & boom_adj_county==0 & boom_msa==0 & g_emp==1, absorb(rssd_id#county county#year) cluster(rssd_id)
est store t1
ivreghdfe lamnt0 l_lasset l_lev l_liqs l_cis l_tier1 l_deps (xboom=xboom_iv) if boom_county==0 & boom_adj_county==0 & boom_msa==0 & g_emp==1, absorb(rssd_id#county county#year) cluster(rssd_id)
est store t2
ivreghdfe lamnt (xboom inter10_cv=xboom_iv inter10_iv) if boom_county==0 & boom_adj_county==0 & boom_msa==0, absorb(rssd_id#county#g_emp county#year) cluster(rssd_id)
est store t3
ivreghdfe lamnt l_lasset l_lev l_liqs l_cis l_tier1 l_deps (xboom inter10_cv=xboom_iv inter10_iv) if boom_county==0 & boom_adj_county==0 & boom_msa==0, absorb(rssd_id#county#g_emp county#year) cluster(rssd_id)
est store t4

/*Compute the overall R-Squared for each regression above*/
matrix R=J(1,4,0)
forval i=1/4{
cap drop e_sample 
cap drop yy
est restore t`i'
gen e_sample=e(sample)
local rss=e(rss)
local depvar=e(depvar)
cap sum `depvar' if e_sample==1
gen yy=(`depvar'-r(mean))^2
cap total yy if e_sample==1
matrix r=e(b)
matrix R[1,`i']=1-`rss'/r[1,1]
}
cap drop yy
matrix list R
